<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <title>Document</title>
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link rel="stylesheet" type="text/css" href="css/mui.min.css"/>
</head>
<body>

    <button type="button" id="btn">更换头像</button>
    <script src="js/mui.min.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript">
    mui.init();
    var btn = document.getElementById('btn');
    btn.addEventListener('tap',function(){
    	var btnArray = [{title:"照相机"},{title:"相册"}]; //选择按钮  1 2 3
		plus.nativeUI.actionSheet( {
			title:"请选择",
			cancel:"取消", // 0
			buttons:btnArray
			}, 
			function(e){
				var index = e.index; // 
				switch (index){
					case 1:
						//写自己的逻辑
						camera();
					break;
					case 2:
						album();
					break;
				}
		} );
    });
    //相册
    function album(){
    	plus.gallery.pick( function(path){
    
		    //img.src = path;//获得图片路径
		    alert(path);
		}, function ( e ) {
		    console.log( "取消选择图片" );
		}, {filter:"image"} );
    }
    //照相机
    function camera(){
    	var cmr = plus.camera.getCamera();
		cmr.captureImage( function ( p ) {
				//成功
				plus.io.resolveLocalFileSystemURL( p, function ( entry ) {
			
				    var img_name = entry.name;//获得图片名称
				    var img_path = entry.toLocalURL();//获得图片路径
				
				}, function ( e ) {
					console.log( "读取拍照文件错误："+e.message );
				} );
				
			}, function ( e ) {
				console.log( "失败："+e.message );
		}, {filename:'_doc/camera/',index:1} ); //  “_doc/camera/“  为保存文件名
    }
    </script>
</body>
</html>
